﻿module TrainingData.PolarHrm.HrmTests

open System

open Xunit

open TrainingData.Common.UnitsOfMeasure
open TrainingData.PolarHrm
open TrainingData.PolarHrm.Hrm

[<Fact>]
let ``Ensure HRM file version is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal(106, hrm.Parameters.Version)

[<Fact>]
let ``Ensure HRM file monitor is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal(0, hrm.Parameters.Monitor)

[<Fact>]
let ``Ensure HRM file start time is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal(DateTime(2012, 08, 09, 17, 33, 31), hrm.Parameters.StartTime)

[<Fact>]
let ``Ensure HRM file duration is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal(TimeSpan(0, 0, 16, 20, 600), hrm.Parameters.Duration)

[<Fact>]
let ``Ensure HRM file mode is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal({ Units = Euro; Speed = true; Cadence = true; Altitude = false; Power = false; PowerBalance = false }, hrm.Parameters.Mode)

[<Fact>]
let ``Ensure HRM file interval is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal(TimeSpan(0, 0, 5), hrm.Parameters.Interval)

[<Fact>]
let ``Ensure HRM file lap times are parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load

    Assert.Equal(2, hrm.LapTimes.Length)

    let first::second::_ = hrm.LapTimes

    Assert.Equal(TimeSpan(0, 0, 1, 28, 600),  first.Time)
    Assert.Equal(93m<beat/min>,               first.CurrentHR)
    Assert.Equal(0m<beat/min>,                first.MinimumHR)
    Assert.Equal(95m<beat/min>,               first.MeanHR)
    Assert.Equal(101m<beat/min>,              first.MaximumHR)

    Assert.Equal(TimeSpan(0, 0, 16, 20, 600), second.Time)
    Assert.Equal(137m<beat/min>,              second.CurrentHR)
    Assert.Equal(0m<beat/min>,                second.MinimumHR)
    Assert.Equal(132m<beat/min>,              second.MeanHR)
    Assert.Equal(162m<beat/min>,              second.MaximumHR)

[<Fact>]
let ``Ensure Cycling HRM data is parsed correctly`` () =
    let hrm = HrmTestData.cyclingExample |> Hrm.load
    
    Assert.Equal(196, hrm.Data.Length)
    failwith "Need more tests here"
    ()
    